package com.example.smartpark.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.smartpark.model.ParkingSpace;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 车位Mapper接口
 */
@Mapper
public interface ParkingSpaceMapper extends BaseMapper<ParkingSpace> {
    
    /**
     * 统计停车场空闲车位数量
     * 
     * @param parkingLotId 停车场ID
     * @return 空闲车位数量
     */
    @Select("SELECT COUNT(*) FROM parking_space WHERE parking_lot_id = #{parkingLotId} AND status = 0 AND deleted = 0")
    int countAvailableSpaces(@Param("parkingLotId") Integer parkingLotId);
    
    /**
     * 更新停车场可用车位数量
     * 
     * @param parkingLotId 停车场ID
     * @param availableSpaces 可用车位数
     * @return 更新行数
     */
    @Update("UPDATE parking_lot SET available_spaces = #{availableSpaces} WHERE id = #{parkingLotId}")
    int updateParkingLotAvailableSpaces(@Param("parkingLotId") Integer parkingLotId, @Param("availableSpaces") Integer availableSpaces);
} 